package com.just521.xinshoutong.helper;

import java.util.HashMap;
import java.util.Iterator;

import android.app.Activity;

import com.just521.xinshoutong.http.HttpHelperWraper.HttpRequestParam;
import com.just521.xinshoutong.http.NetHelperBase;


	
	public  class  UserHelper extends NetHelperBase{
		static  HashMap<String,HashMap<String, Object>> usercache = new HashMap<String,HashMap<String, Object>>() ;
		
		
		public UserHelper(Activity context, boolean show_wait_dlg) {
			super(context, show_wait_dlg);
			
		}
		
		public static HashMap<String, Object> get_user(String userid){
			return usercache.get(userid);
		}
		
		public void getinfo(String userid, String selfid){
			if(null != usercache.get(userid)){
				if(mUpdateListener != null){
					mUpdateListener.UserHelpersucc();
				}
			}else{
				getinfo_net(userid, selfid);
			}
		}
		
		public void getinfo_net(String userid, String selfid){
			insert_param("userid",userid);
			insert_param("selfid",selfid);
			
			request_server_yibu("getUserInfo");
		}
				
		
		public void process_result(HttpRequestParam param)
		{
			
			HashMap<String, Object> user = new HashMap<String, Object>();
			
			HashMap<String, Object> info = param.nodesresult;
			Iterator<String> it = info.keySet().iterator();
			while(it.hasNext()){
				String key = it.next();
				Object value = info.get(key);
				user.put(key, value);
			}
			usercache.put((String)user.get("userid"), user);
			
			if(mUpdateListener != null){
				mUpdateListener.UserHelpersucc();
			}
			
		}
		
		
		public void process_error(String err)
		{
			
		}
		
		////////////////////////////////////////////////////////////////////////////////////////////////////
		//对外通知接口
	    private 	UserHelpersucc mUpdateListener=null;
	    private 	UserHelperfail mErrorListener=null;
	   public interface UserHelpersucc {  
	        void UserHelpersucc( );  
	    }  
	    public void setUserHelpersucc(UserHelpersucc listener) {  
	    	mUpdateListener = listener;  
	    }   
	 
	    public interface UserHelperfail {  
	        void UserHelperfail( );  
	    }  
	    public void setUserHelperfail(UserHelperfail listener) {  
	    	mErrorListener = listener;  
	    }   
		
	    
		
	};